set scheme plotplainblind


cap log close
version 14
clear 
clear matrix
set more off


 ****************************
 *							*
 *		  Table 1		    * 
 *							*
 ****************************

use "caiwang_main.dta", clear

* Panel A: Administrative Data
sum pfm_totalscore if rand_treat_mgt ==1 & year==2016 & present_next==1 /*Col 1: treatment mean*/  
sum pfm_totalscore if rand_treat_mgt ==0 & year==2016 & present_next==1 /*Co1 2: control mean*/
sum pfm_totalscore if year==2016 & present_next==1  /*Co1 3: N*/ 
xi: regress pfm_totalscore rand_treat_mgt if year==2016 & present_next==1 , cluster(team_al) /*Col 4: p-value*/ 

sort team_al year ID
sum KPI_ttlsc if rand_treat_mgt ==1 & year==2016 & (team_al!=team_al[_n-1] | year!=year[_n-1])  /*Col 1: treatment mean*/  
sum KPI_ttlsc if rand_treat_mgt ==0 & year==2016 & (team_al!=team_al[_n-1] | year!=year[_n-1])  /*Co1 2: control mean*/
sum KPI_ttlsc if year==2016 & (team_al!=team_al[_n-1] | year!=year[_n-1]) /*Co1 3: N*/ 
xi: regress KPI_ttlsc rand_treat_mgt if year==2016 & (team_al!=team_al[_n-1] | year!=year[_n-1]) , cluster(team_al) /*Col 4: p-value*/ 

* Panel B: Survey data
foreach var of varlist age male ihsedu tenurejmc_precise married G1_liferating work_satis igoodhealth panas_pos panas_neg totalearn_avg2 bonus_avg2 iE3_scl_out {
	des `var'
	sum `var' if rand_treat_mgt ==1 & year==2016 & present_next==1 /*Col 1: treatment mean*/  
	sum `var' if rand_treat_mgt ==0 & year==2016 & present_next==1 /*Co1 2: control mean*/
	sum `var' if year==2016 & present_next==1  /*Co1 3: N*/ 
	xi: regress `var' rand_treat_mgt if year==2016 & present_next==1 , cluster(team_al) /*Col 4: p-value*/ 
}
 
 ****************************
 *							*
 *		  Table 2		    *
 *							*
 ****************************

use "caiwang_main.dta",clear


*Col 1: Workers (Survey Sample)
xi:  reg leave rand_treat_mgt rand_treat_peer i.rand_strata_ind if year==2016,cluster(team_al)

* Col 2: Workers (Survey Sample) with lag
xi:  reg leave rand_treat_mgt rand_treat_peer i.rand_strata_ind teamavg_leave_beforeint if year==2016,cluster(team_al)

*Col 3: Managers 
xi: regress leave rand_treat_mgt rand_treat_peer i.rand_strata_ind if year==2016 & C7_role_baseline==3 ,cluster(team_al)

*Col 4: Workers (Expanded Sample table 10.1)
use "pfm_expanded.dta",replace

label var teamavg_leave_beforeint "Lag Team Turnover"
xi: regress leave2 rand_treat_mgt rand_treat_peer i.rand_strata_ind if (oldsample2==1|newsample==1), cluster(team_pfm) 	

* Col 5: Workers (Exapnded Sample) with lag
xi: regress leave2 rand_treat_mgt rand_treat_peer i.rand_strata_ind teamavg_leave_beforeint if (oldsample2==1|newsample==1), cluster(team_pfm) 	

 
 ****************************
 *							*
 *		Table 3 and O1.4    *
 *							*
 ****************************

use "upperlevel_evals.dta", clear

**** Table O1.4 summary statistics

** Panel A	
local list "upper_total upper_production upper_incentives upper_fairness upper_evaluation upper_training upper_delegation"

foreach x of varlist `list' {
	sum `x' if team_rand_treat_mgt ==1 & year==2016 & post==0, d /*Col1: treatment mean*/
	sum `x' if team_rand_treat_mgt ==0 & year==2016 & post==0, d /*Col2: control mean*/
	sum `x' if year==2016 & post==0 /*Col3: N*/
	xi: regress `x' team_rand_treat_mgt if year==2016 & post==0, cluster(team_al) /*Col4: p-value*/
}


** Panel B
local list "upperprob_hiring upperprob_turnover upperprob_organization upperprob_target upperprob_RD upperprob_market"

foreach x of varlist `list' {
	sum `x' if team_rand_treat_mgt ==1 & year==2016 & post==0,d /*Col1: treatment mean*/	
	sum `x' if team_rand_treat_mgt ==0 & year==2016 & post==0,d /*Col2: control mean*/
	sum `x' if year==2016 & post==0 /*Col3: N*/
	xi: regress `x' team_rand_treat_mgt if year==2016 & post==0, cluster(team_al) /*Col4: p-value*/
}


** Panel C
local list "uppersol_incwage uppersol_equipment uppersol_training uppersol_advertisement uppersol_innovation uppersol_relfeedback"

foreach x of varlist `list' {
	sum `x' if team_rand_treat_mgt ==1 & year==2016 & post==0,d /*Col1: treatment mean*/	
	sum `x' if team_rand_treat_mgt ==0 & year==2016 & post==0,d /*Col2: control mean*/
	sum `x' if year==2016 & post==0 /*Col3: N*/
	xi: regress `x' team_rand_treat_mgt if year==2016 & post==0, cluster(team_al) /*Col4: p-value*/
}


**** Table 3: Impact of evaluation mamagers 
duplicates drop

* Panel A
local list1 "avgupper_total avgupper_production avgupper_incentives avgupper_fairness avgupper_evaluation avgupper_training avgupper_delegation "
* Panel B
local list2 "avgupperprob_hiring avgupperprob_turnover avgupperprob_organization avgupperprob_target avgupperprob_RD avgupperprob_market"
* Panel C
local list3 "avguppersol_incwage avguppersol_equipment avguppersol_training avguppersol_advertisement avguppersol_innovation avguppersol_relfeedback"

gen lagvar=.
forvalues a = 1/3 {
	local listactive `list`a''
	di "`listactive'"
	
	foreach var of varlist `listactive' {
		qui bysort team_aligned (post): replace lagvar=`var'[_cons]
		regress `var' team_rand_treat_mgt team_rand_treat_peer lagvar i.rand_strata_team if post==1, cluster(team_aligned)	
	}
}


 
 ****************************
 *							*
 *		  Table 4		    *
 *							*
 **************************** 
 
use "caiwang_main.dta",clear 

local list "pfm_totalscore pfm_Production pfm_Safety pfm_Quality pfm_Attitude pfm_Routine pfm_Attendance obj_pfm rela_pfm examvalue"

local i = 1 
foreach var of varlist `list' {
	replace lagdepvar = lag_`var'
	if (`i'<10) {
		reg `var' rand_treat_mgt rand_treat_peer lagdepvar i.rand_strata_ind if year==2017, cluster(team_al)
	}
	else if (`i'==10) {
		xi: reg `var' rand_treat_mgt rand_treat_peer i.rand_strata_ind if year==2017 & pfm_totalscore~=. & lag_pfm_totalscore~=. & NumExam~=0,cluster(team_al)
	}
	local i = `i' + 1
}

 ****************************
 *							*
 *		  Table 5		    *
 *							*
 **************************** 

use "caiwang_main.dta",clear 

sort team_al year 

foreach var in KPI_ttlsc KPI_sc_cateProduction KPI_sc_cateManagement_avg3 KPI_sc_cateEquipment_avg3 KPI_sc_cateQuality_avg3 KPI_sc_cateSafety_avg3 {
	replace lagdepvar = lag_`var'
	xi: regress `var' team_rand_treat_mgt team_rand_treat_peer lagdepvar i.rand_strata_team if year==2017 & (team_al!=team_al[_n-1] | year!=year[_n-1]),cluster(team_al)
}

 ****************************
 *							*
 *		  Table 6		    *
 *							*
 ****************************   
 
use "caiwang_main.dta",clear

*Panel A: Workers
*Cols 1-2
foreach var in totalearn_avg2 bonus_avg2 {
	replace lagdepvar = lag_ihs`var'
	xi: regress ihs`var' rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator lagdepvar i.lag_survey_month2016 i.survey_month2017 if year==2017 & C7_role<=3,cluster(team_al)
}
*Cols 3-8
foreach var in  G1_liferating wrk_sat_sum panas_pos panas_neg igoodhealth happiness1 {
	replace lagdepvar = lag_`var'
	xi: regress `var' rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator lagdepvar if year==2017,cluster(team_al)
}

*Panel B: Managers
*Cols 1-2
foreach var in totalearn_avg2 bonus_avg2 {
	replace lagdepvar = lag_ihs`var'
	xi: regress ihs`var' rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator lagdepvar i.lag_survey_month2016 i.survey_month2017 if year==2017 & C7_role==3,cluster(team_al)
}
*Cols 3-8
foreach var in G1_liferating wrk_sat_sum panas_pos panas_neg igoodhealth happiness1 {
	replace lagdepvar = lag_`var'
	xi: regress `var' rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator lagdepvar if year==2017 & C7_role_baseline==3,cluster(team_al)
}

 ****************************
 *							*
 *		  Table 7   	    *
 *							*
 ****************************   

use "caiwang_main.dta", clear 

* Panel A: Work Satisfaction 
local list1 "F1_wksatis F2_wksatis F3_wksatis F5_wksatis F6_wksatis F7_wksatis F8_wksatis F9_wksatis F11W_wksatis F12_wksatis F13_wksatis F14_wksatis F15_wksatis F16W_wksatis F17_wksatis"

foreach var of varlist  `list1' {
    replace lagdepvar = lag_`var'
    regress `var' rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator lagdepvar if year==2017,cluster(team_al)
}

* Panel B: Socializing between Workers and Managers
xi: regress social rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator if year==2017,cluster(team_al)

 ****************************
 *							*
 *		  Table 8		    *
 *							*
 ****************************  
 
use "caiwang_main.dta",clear 

sort team_al year
*Columns 1-3
replace treat = team_rand_treat_mgt
replace peertreat = team_rand_treat_peer
foreach var of varlist KPI_ttlsc  KPI_sc_cateProduction {
	replace lagdepvar = lag_`var'
	xi: reg `var' avg_mgr_scoreaware D6W_score_fo peertreat i.enumerator lagdepvar if treat ==1 & year==2017,cluster(team_al)
}

*Columns 4-5
replace treat = rand_treat_mgt
replace peertreat = rand_treat_peer
foreach var in G1 happiness1 {
	replace lagdepvar = lag_`var'
	xi: reg `var' avg_mgr_scoreaware D6W_score_fo peertreat i.enumerator lagdepvar if treat==1 & year==2017,cluster(team_al)
}
 
 ****************************
 *							*
 *		  Table 9		    *
 *							*
 **************************** 

use "caiwang_main.dta",clear 

* column 1
foreach var in pfm_totalscore {
	xi: reg `var' team_rand_treat_mgt team_rand_treat_peer i.rand_strata_ind if year==2017 & start_postendint==1, cluster(team_al)
}

* column 2-6
foreach var in G1 happiness iF5_wksatis iF7_wksatis iF14_wksatis iF16W_wksatis {
	xi: reg `var' team_rand_treat_mgt team_rand_treat_peer i.rand_strata_ind i.enumerator if year==2017 & start_postendint==1, cluster(team_al)
}


 ****************************
 *							*
 *		  Table 10		    *
 *							*
 **************************** 

use "caiwang_main.dta",clear

* Panel A: Network spillover
replace treat = team_rand_treat_mgt
replace peertreat = team_rand_treat_peer
foreach var of varlist KPI_ttlsc KPI_sc_cateProduction  {
	*winsor2 `var', replace cuts(5 95)
	replace lagdepvar = lag_`var'
	xi: reg `var' SN_treat_mgt SN_size_unq ittXcorenetwork ittXSN_size_unq treat peertreat i.rand_strata_team lagdepvar if year==2017,cluster(team_al)
}

* Panel B: Upstream spillover
use "spillover_upstream.dta", clear 

foreach var in KPI_ttlscpp KPI_sc_cateProductionpp{
	replace lagdepvar = lag`var'
	xi: reg `var' treat_mgt_upstream_num upstream_num team_rand_treat_mgt team_rand_treat_peer lagdepvar i.rand_strata_team if post==1, cluster(id)	
}
		
* Panel C: Neighbour spillover
foreach var in KPI_ttlscpp KPI_sc_cateProductionpp{
	replace lagdepvar = lag`var'
	xi: reg `var' treat_mgt_nbr nbr_num team_rand_treat_mgt team_rand_treat_peer lagdepvar i.rand_strata_team if post==1, cluster(id)
}	


*************************************************
 *							                    *
 *		       Table O1.3		                * 
 *							                    *
 ************************************************

use "caiwang_main.dta", clear

* Panel A: Worker Performance
foreach var of varlist pfm_* {
	des `var'
	sum `var' if rand_treat_mgt ==1 & year==2016 & present_next==1 /*Col 1: treatment mean*/  
	sum `var' if rand_treat_mgt ==0 & year==2016 & present_next==1 /*Co1 2: control mean*/
	sum `var' if year==2016 & present_next==1  /*Co1 3: N*/ 
	xi: regress `var' rand_treat_mgt if year==2016 & present_next==1 , cluster(team_al) /*Col 4: p-value*/ 
} 

* Panel B: Team-Level KPI
sort team_al year ID
local list "KPI_sc_cateProduction KPI_sc_cateManagement KPI_sc_cateEquipment KPI_sc_cateQuality KPI_sc_cateSafety"
foreach x of varlist `list' {
	sum `x' if rand_treat_mgt ==1 & year==2016 & (team_al!=team_al[_n-1] | year!=year[_n-1])  /*Col 1: treatment mean*/  
	sum `x' if rand_treat_mgt ==0 & year==2016 & (team_al!=team_al[_n-1] | year!=year[_n-1])  /*Co1 2: control mean*/
	sum `x' if year==2016 & (team_al!=team_al[_n-1] | year!=year[_n-1]) /*Co1 3: N*/ 
	xi: regress `x' rand_treat_mgt if year==2016 & (team_al!=team_al[_n-1] | year!=year[_n-1]) , cluster(team_al) /*Col 4: p-value*/ 
}

 ****************************
 *							*
 *		  Table O1.2	    *
 *							*
 **************************** 

use KPI_Performance_allmonths,clear

keep if minyr==2016 & maxyr==2017 & minmon<9
sort plant team_al

* summary stataistics table
local list "modeKPI_wgt_cateProduction modeKPI_wgt_cateManagement modeKPI_wgt_cateEquipment modeKPI_wgt_cateQuality modeKPI_wgt_cateSafety"

foreach var of varlist `list' {
	des `var'
	sum `var' if team_rand_treat_mgt ==0 & team_al!=team_al[_n-1] /*Col1: treatment mean*/
	sum `var' if team_rand_treat_mgt ==1 & team_al!=team_al[_n-1] /*Col2: control mean*/
	sum `var' if team_al!=team_al[_n-1] /*Col3: N*/
	xi: regress `var' team_rand_treat_mgt if team_al!=team_al[_n-1], cluster(team_al) /*Col4: p-value*/
}

 ****************************
 *							*
 *		  Table O2.1		*
 *							*
 ****************************
use KPI_Performance_allmonths,clear 

drop if plant==""|team_aligned==""

* full sample pre intervention + control Team 
reg KPI_ttlsc pfm_totalscore if rand_strata_team!=. & year==2016&month<=8 ,cluster(team_al)
reg KPI_ttlsc pfm_totalscore i.month if rand_strata_team!=. & year==2016&month<=8 ,cluster(team_al)

correl KPI_ttlsc pfm_totalscore if rand_strata_team!=. & year==2016&month<=8

* control Team (Pre & Post Intervention)
reg KPI_ttlsc  pfm_totalscore if rand_strata_team!=. & team_rand_treat_mgt==0 ,cluster(team_al)
reg KPI_ttlsc  pfm_totalscore i.month if rand_strata_team!=. & team_rand_treat_mgt==0 ,cluster(team_al)

correl KPI_ttlsc pfm_totalscore if rand_strata_team!=. & team_rand_treat_mgt==0 



 
 ****************************
 *							*
 *		  Table O1.7 	    *
 *							*
 **************************** 
 
use "caiwang_main.dta", clear

local list1 "F1_wksatis F2_wksatis F3_wksatis F5_wksatis F6_wksatis F7_wksatis F8_wksatis F9_wksatis F11W_wksatis F12_wksatis F13_wksatis F14_wksatis F15_wksatis F16W_wksatis F17_wksatis"

foreach var of varlist  `list1' {
  sum `var' if rand_treat_mgt == 1 & year==2016 & leave!=1 /*Col1: treatment mean */ 
  sum `var' if rand_treat_mgt == 0 & year==2016 & leave!=1 /*Col2: control mean*/
  regress `var' rand_treat_mgt if year==2016 & leave!=1, cluster(team_al) /*Col3: p-value*/
  sum `var' if year==2016  & leave!=1 /*Col4: N*/
}
	

 ****************************
 *							*
 *		  Table O1.8  	    *
 *							*
 **************************** 
 
use KPI_Performance_allmonths,clear

* generate leads and lags 
char date_ym[omit]679  /* set Aug 2016 as the omitted period */
xi i.date_ym|rand_treat_mgt, prefix(_I)
rename _IdatXran_* _IperXmgt_*

foreach i of numlist 676/678 {
	local k= 680-`i'
	label var _IperXmgt_`i' "-`k' month X Treat"
}

foreach i of numlist 680/690 {
	local k=`i'- 680
	label var _IperXmgt_`i' "`k' month X Treat"
}

* regressions: w/o peer treat
foreach var in pfm_totalscore pfm_Production pfm_Safety pfm_Quality pfm_Attitude pfm_Routine pfm_Attendance obj_pfm rela_pfm {
	areg `var' _IperXmgt_676-_IperXmgt_690 i.rand_strata_ind i.date_ym, absorb(A2_worker_ID) cluster(team_al)
}


 ****************************
 *							*
 *		  Table O1.9	    *
 *							*
 **************************** 

use KPI_Performance_allmonths,clear

* keep only one KPI record for each team every month
gsort plant team_aligned year month KPI_ttlsc KPI_sc_cateProduction KPI_sc_cateManagement KPI_sc_cateEquipment KPI_sc_cateQuality KPI_sc_cateSafety A2_worker_ID
drop if plant==plant[_n-1] & team_al==team_al[_n-1] & year==year[_n-1] & month==month[_n-1] 

* generate leads and lags
char date_ym[omit]679  /* set Aug 2016 as the omitted period */
xi i.date_ym|team_rand_treat_mgt, prefix(_I) 
rename _IdatXtea_* _IperXmgt_*

foreach i of numlist 676/678 {
	local k= 680-`i'
	label var _IperXmgt_`i' "-`k' month X Treat"
}

foreach i of numlist 680/690 {
	local k=`i'- 680
	label var _IperXmgt_`i' "`k' month X Treat"
}

xtset ID_team date_ym
foreach var in KPI_ttlsc KPI_sc_cateProduction KPI_sc_cateManagement KPI_sc_cateEquipment KPI_sc_cateQuality KPI_sc_cateSafety {
	xtreg `var' _IperXmgt_676-_IperXmgt_690 i.rand_strata_team i.date_ym i.KPI_vrsn, fe cluster(ID_team)
}


 ****************************
 *							*
 *		  Table O1.10       *
 *							*
 ****************************   
 
use "caiwang_main.dta", clear 

*Col 1: Socialize manager
replace lagdepvar = lag_E3_scl_out
xi: regress iE3_scl_out rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator if year==2017,cluster(team_al)

*Col 2: WeChat manager
xi: regress iE2_1_moments_fo rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator if year==2017,cluster(team_al)

 
 ****************************
 *							*
 *		   Table O3.1		*
 *							*
 **************************** 

use "caiwang_main.dta",clear 

** Columns 1-2 (team-level data)	
replace treat=team_rand_treat_mgt
replace peertreat=team_rand_treat_peer
replace ittXbonus = team_rand_treat_mgt * mng_bonus_above	
		
sort team_al year
foreach var of varlist KPI_ttlsc KPI_sc_cateProduction {
		winsor2 `var', replace cuts(5 95)
		replace lagdepvar = lag_`var'
		xi: reg `var' ittXbonus treat mng_bonus_above peertreat i.rand_strata_team lagdepvar if year==2017 & (team_al!=team_al[_n-1] | year!=year[_n-1]), cluster(team_al)
}
		
** Columns 3-4 (worker-level data)			
replace treat=rand_treat_mgt
replace peertreat=rand_treat_peer
replace ittXbonus = rand_treat_mgt * mng_bonus_above
foreach var in G1 happiness1  {
		replace lagdepvar = lag_`var'
		xi: reg `var' ittXbonus treat mng_bonus_above peertreat i.rand_strata_ind i.enumerator lagdepvar if year==2017,cluster(team_al)
}



 ****************************
 *							*   
 *		  Table O1.11	    *
 *							*
 ****************************   

use "caiwang_main.dta",clear 

*Worker's Awareness
*columns 1-2
foreach var in D6W_score_fo scoreaffectwage_w { 
	 des `var'
	 xi: regress `var' rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator if year==2017 & C7_role_baseline<3,cluster(team_al)
}

*Manager's Awareness 
*columns 4-5
foreach var in D6M_score scoreaffectwage_m {
	des `var'
	xi: regress `var' rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator if year==2017 & C7_role_baseline==3,cluster(team_al)
}


 ****************************
 *							*
 *		  Table O1.12	    *
 *							*
 **************************** 
 
use "caiwang_main.dta",clear

* generate coefficient table
local list "age male ihsedu married referred wrkexp local16"
foreach var of varlist `list' {
    * Treatment team
	sum `var' if year==2017 & newent2==1 & team_rand_treat_mgt == 1 /*Col1 & Col4: treatment mean & N*/
	
	* Control team
	sum `var' if year==2017 & newent2==1 & team_rand_treat_mgt == 0 /*Col2 & Col5: control mean & N*/

	* P values (diff between col 1 and 2)
	regress `var' team_rand_treat_mgt if year==2017 & newent2==1 & (team_rand_treat_mgt!=.), cluster(team_al) /*Col3: p-value*/
	}
		
	
 ****************************
 *							*
 *		  Table O4.1	    *
 *							*
 **************************** 
use "caiwang_main.dta",clear 

sort team_al year 

replace treat = rand_treat_mgt
replace peertreat = rand_treat_peer

*col 1
xi: regress diff_manager treat peertreat i.rand_strata_ind if year==2017,cluster(team_al)

*col 2
xi: regress changeout_team treat peertreat i.rand_strata_ind if year==2017,cluster(team_al)

replace treat = team_rand_treat_mgt
replace peertreat = team_rand_treat_peer

*col 3
xi: regress sum_changeteam treat peertreat i.rand_strata_team if (team_al!=team_al[_n-1] | year!=year[_n-1]) & year==2017,cluster(team_al) 

*col 4 
xi: regress teamsize treat peertreat i.rand_strata_team lag_teamsize if (team_al!=team_al[_n-1] | year!=year[_n-1]) & year==2017,cluster(team_al)



 ****************************
 *							*
 *		  Table O4.2	    *
 *							*
 **************************** 

use "caiwang_main.dta",clear 

label var KPI_ttlsc "Total KPI"
label var KPI_sc_cateProduction "Production KPI"
label var KPI_sc_cateManagement "Management KPI"
label var KPI_sc_cateEquipment "Equipment KPI"
label var KPI_sc_cateQuality "Quality KPI"
label var KPI_sc_cateSafety "Safety KPI"
label var G1_liferating "Life Rating"
label var pfm_totalscore_avg3 "Total PFM"
label var pfm_Production_avg3 "Production PFM"
label var pfm_Quality_avg3 "Quality PFM"
label var pfm_Attitude_avg3 "Attitude PFM"
label var pfm_Routine_avg3 "Routine PFM"
label var pfm_Attendance_avg3 "Attendance PFM"
label var pfm_Safety_avg3 "Safety PFM"
label var tenurejmc_precise "Firm Tenure"

sort ID year	
local list "KPI_ttlsc KPI_sc_cateProduction KPI_sc_cateManagement KPI_sc_cateEquipment KPI_sc_cateQuality KPI_sc_cateSafety pfm_totalscore pfm_Production pfm_Safety pfm_Quality pfm_Attitude pfm_Routine pfm_Attendance tenurejmc_precise G1_liferating happiness"
foreach var of varlist `list' {
	sum `var' if year==2016 & changeout_team==0    /*col 1: team stayers mean*/
	sum `var' if year==2016 & changeout_team==1   /*col 2: team changers mean*/
	regress `var' changeout_team if year==2016 & (changeout_team!=.), cluster(team_al) /*col 3: p-value diff*/
}

 ****************************
 *							*
 *		  Table O4.3       	*
 *							*
 ****************************
 
use "caiwang_main.dta",clear 
sort ID year

label var F5_wksatis "Others"
label var F7_wksatis "Manager"
label var F14_wksatis "Manager"
label var F16W_wksatis_agree "No"

* performance outcomes	
foreach var in pfm_totalscore {
	replace lagdepvar = lag_`var'
	xi: regress `var' rand_treat_mgt rand_treat_peer i.rand_strata_ind lagdepvar if year==2017 & tmchange==0,cluster(team_al)
}

* satisfaction
foreach var in F5_wksatis F7_wksatis F14_wksatis F16W_wksatis_agree {
replace lagdepvar=lag_`var'
	xi: reg `var' rand_treat_mgt rand_treat_peer i.rand_strata_ind lagdepvar i.enumerator if year==2017 & tmchange==0, cluster(team_al)
}

* well-being outcomes 
foreach var in  G1_liferating {
	replace lagdepvar = lag_`var'
	xi: regress `var' rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator lagdepvar if year==2017 & tmchange==0,cluster(team_al)
}

* well-being index
replace lagdepvar=lag_happiness1
xi: regress happiness1 rand_treat_mgt rand_treat_peer i.rand_strata_ind i.enumerator lagdepvar if year==2017 & tmchange==0,cluster(team_al)

 
 ****************************
 *							*
 *		  Table	O4.4	    *
 *							*
 **************************** 
use "caiwang_main.dta",clear 

label var KPI_ttlsc "Total KPI"
label var KPI_sc_cateProduction "Production KPI"
label var KPI_sc_cateManagement "Management KPI"
label var KPI_sc_cateEquipment "Equipment KPI"
label var KPI_sc_cateQuality "Quality KPI"
label var KPI_sc_cateSafety "Safety KPI"
label var G1_liferating "Life Rating"
label var pfm_totalscore_avg3 "Total PFM"
label var pfm_Production_avg3 "Production PFM"
label var pfm_Quality_avg3 "Quality PFM"
label var pfm_Attitude_avg3 "Attitude PFM"
label var pfm_Routine_avg3 "Routine PFM"
label var pfm_Attendance_avg3 "Attendance PFM"
label var pfm_Safety_avg3 "Safety PFM"
label var tenurejmc_precise "Firm Tenure"

local list "KPI_ttlsc KPI_sc_cateProduction KPI_sc_cateManagement KPI_sc_cateEquipment KPI_sc_cateQuality KPI_sc_cateSafety pfm_totalscore pfm_Production pfm_Safety pfm_Quality pfm_Attitude pfm_Routine pfm_Attendance tenurejmc_precise G1_liferating happiness "
foreach var of varlist `list' {
	sum `var' if year==2016 & present_next==1   /*col 1 & col4: stayers mean & N*/
	sum `var' if year==2016 & leave==1  /*col 2 & col5: changers mean & N*/
	regress `var' leave if year==2016 & (present_next==1 | leave==1), cluster(team_al) /*col 3: p-value diff*/
	
}
	
 ****************************
 *							*
 *		  Table O1.13		*
 *							*
 ****************************  

use "caiwang_main.dta",clear

*Panel A
local list "D9W_discman_fo D11W_disccolle_fo D14W_discothe hold"
foreach x in `list' {
	sum `x', d
}

*Panel B
local list "D8M_discwork D11M_discman D14M_discsuper "
foreach x in `list' {
	sum `x', d
}

 ****************************
 *							*
 *		  Figure 1		    *
 *							*
 **************************** 

use "caiwang_main.dta", clear

* individual level variable distributions 
sort ID 
quietly by ID:  gen dup = cond(_N==1,0,_n) 

	** calculate pre-post change
	gen pfm_ttl_change = pfm_totalscore_avg3 - lag_pfm_totalscore_avg3  if year==2017 & dup > 0 & pfm_totalscore_avg3 >= 95 & pfm_totalscore_avg3 <= 105 & ///
                         lag_pfm_totalscore_avg3 >= 95 & lag_pfm_totalscore_avg3 <= 105
						 
twoway (kdensity pfm_ttl_change if rand_treat_mgt == 1, lpattern(solid) lcolor(red)) ///  /*treated*/
	   (kdensity pfm_ttl_change if rand_treat_mgt == 0,  /// /*control*/
	   lpattern(dash) lcolor(black) xlabel(-6(1)5) fcolor(none) xtitle("") ytitle("Kernel density")), legend(order(1 "Treated" 2 "Control"))

 
	
* team level variable distribution
use "caiwang_main.dta", clear

	** Collapse to team level 
	sort team_al year
	drop if (team_al==team_al[_n-1] & year==year[_n-1])
	
	** calculate pre-post change
    gen KPI_ttl_change = KPI_ttlsc_avg3 - lag_KPI_ttlsc_avg3 if year==2017
	
twoway (kdensity KPI_ttl_change if team_rand_treat_mgt == 1, lpattern(solid) lcolor(red)) /// /*treated*/
		   (kdensity KPI_ttl_change if team_rand_treat_mgt == 0, /// /*control*/  
		   lpattern(dash) lcolor(black) fcolor(none) xtitle("") ytitle("Kernel density")), legend(order(1 "Treated" 2 "Control"))


 ****************************
 *							*
 *		  Figure 2   		*
 *							*
 **************************** 

use "caiwang_main.dta",clear

* keep only one obs. for each ID
drop if leave2==.|studytime==.|studytime<0
gsort ID -studytime year
duplicates drop ID leave2 studytime, force

* declare data to be survival-time data (analysis time scaled to the units of months)
sort ID studytime
stset day_quit, failure(leave2==1) id(ID) origin(day_start) scale(30.5)

* create the Kaplan-Meier curve and Harzard model curve
eststo: stcox rand_treat_mgt rand_treat_peer, vce(cluster team_aligned) efron
predict S0, basesurv
gen S1 = S0^exp(_b[rand_treat_mgt]) // treated
sts gen KM = s, by(rand_treat_mgt)
graph twoway (scatter S0  _t, c(J) ms(none) sort)  /// baseline
       (scatter S1 _t , c(J) ms(none) sort)     /// treated
       (scatter KM _t if rand_treat_mgt, msymbol(circle_hollow))  /// KM treated    
	   (scatter KM _t if !rand_treat_mgt, msymbol(X) /// KM base
       xtitle("Months since the intervention start") ylab(0.85 0.9 to 1) xlab(0 1 to 11) ///
       xline(0, lpattern(solid) lcolor(black)) xline(6,lpattern(longdash_dot) lcolor(black)) xline(8,lpattern(shortdash) lcolor(black)) ///
       text(1 0 "Start of" "Intervention" 1 6 "End of" "Financial" "Incentive", placement(ne) just(left) nobox margin(r-3 b+3) size(small)) ///
       text(1 8 "End of" "Program" , placement(ne) just(left) margin(l+1 b+3) nobox size(small))) , ///
       legend(order(1 "Hazard-Control" 2 "Hazard-Treated" 3 "KM-Control" 4 "KM-Treated") size(small)) graphregion(margin(5 5 5 13))


 ****************************
 *							*
 *		  Figure 3  		*
 *							*
 **************************** 

use KPI_Performance_allmonths,clear

* keep only one record for each team
gsort plant team_aligned year month KPI_ttlsc KPI_sc_cateProduction A2_worker_ID
drop if plant==plant[_n-1] & team_al==team_al[_n-1] & year==year[_n-1] & month==month[_n-1]  

* generate residuals of the eoutcome variables
xtset ID_team date_ym
xtreg KPI_ttlsc,fe 
predict y1_res, res

xtreg KPI_sc_cateProduction, fe 
predict y2_res, res

* collapse the data
sort plant team_al date_ym
collapse (mean) y1_res y2_res, by(team_rand_treat_mgt date_ym)
gen month = date_ym
format month %8.0g
replace month = month - 680

sum y1_res,d
local ymax=r(p99)
graph twoway (connected y1_res month if team_rand_treat_mgt==1) /// 
             (connected y1_res month if team_rand_treat_mgt==0, lpattern(dash) lcolor(red)  ///
			 xtitle("Months Since the Intervetion Starts", size(small)) ///
			 ytitle("Total KPI", size(small)) ///
			 xlab(-4(1)10)   ///
			 xline(0, lpattern(solid) lcolor(black)) xline(5,lpattern(longdash_dot) lcolor(black)) xline(7,lpattern(shortdash) lcolor(black)) ///
			 text(`ymax' 0 "Start of" "Intervention" `ymax' 5 "End of" "Financial" "Incentive", placement(nw) just(left) nobox margin(r b+1) size(small)) ///
			 text(`ymax' 7 "End of" "Program" , placement(ne) just(left)margin(l+1 b+1) nobox size(small))), ///
			 legend(order(1 "Treated" 2 "Control" ) size(small)) graphregion(margin(5 5 5 10))
			 


use KPI_Performance_allmonths,clear

* generate residuals of the eoutcome variables
areg pfm_totalscore,absorb(A2_worker_ID) 
predict y4_res, res

* collapse the data
sort A2_worker_ID date_ym
collapse (mean) y4_res, by(rand_treat_mgt date_ym)
gen month = date_ym
format month %8.0g
replace month = month - 680

sum y4_res if rand_treat_mgt!=. ,d
local ymax=r(p99)
graph twoway (connected y4_res month if rand_treat_mgt==1) ///
             (connected y4_res month if rand_treat_mgt==0, lpattern(dash) lcolor(red)  ///
			 xtitle("Months Since the Intervention Starts", size(small)) ///
			 ytitle("Total Performance", size(small)) xline(0, lpattern(solid)) xline(5,lpattern(longdash_dot)) xline(7,lpattern(shortdash)) ///
			 xlab(-4(1)10)   ///
			 xline(0, lpattern(solid) lcolor(black)) xline(5,lpattern(longdash_dot) lcolor(black)) xline(7,lpattern(shortdash) lcolor(black)) ///
			 text(`ymax' 0 "Start of" "Intervention" `ymax' 5 "End of" "Financial" "Incentive", placement(nw) just(left) nobox margin(r b+11) size(small)) ///
			 text(`ymax' 7 "End of" "Program" , placement(ne) just(left)margin(l+1 b+11) nobox size(small))), ///
			 legend(order(1 "Treated" 2 "Control" ) size(small))  graphregion(margin(5 5 5 12)) 



 ****************************
 *							*
 *		  Figure O4.1		*
 *							*
 **************************** 

use "caiwang_main.dta", clear 

* test setup
replace rand_strata_team = 23 if rand_strata_team == .   
forvalues i = 1/200 {  /*Will generate 200 placebo treatment variables*/
	qui gen placebo_treat`i' = 0 
	forvalues strata = 1/23 { /*Run the random treatment assignment procedure within each strata*/
		set seed 123`i'`stata'
		qui gen double u = runiform() if year == 2016 & rand_strata_team == `strata' & flag == 1
		qui set sortseed 345`i'`stata' 
		sort u /*observations in the strata are now ordered randomly*/
		qui gen n = _n if year == 2016 & rand_strata_team == `strata' & u != . & flag == 1
		qui count if year == 2016 & rand_strata_team == `strata' & flag == 1 /*r(N) stores the count*/
		qui replace placebo_treat`i' = 1 if year == 2016 & rand_strata_team == `strata' & flag == 1 & n <= `r(N)'/2 /*assign treatment to top half of randomly ordered observations*/
		drop u n 
	}
	sort team_al year 
	qui egen placebo_treat_new`i' = max(placebo_treat`i'), by(team_al)
	qui drop placebo_treat`i' 
	qui rename placebo_treat_new`i' placebo_treat`i' 
} 

* placebo test for workers turnover (Individual level)
unab treatmentvarlist: rand_treat_mgt placebo_treat*
di "`treatmentvarlist'"
sort team_al year 

forvalues i = 1/201 {
		local treatmentvar : word `i' of `treatmentvarlist'
		qui xi:  reg leave `treatmentvar' rand_treat_peer i.rand_strata_ind if year==2016,cluster(team_al) 
		estimates store r`i'
}
	
# delimit ; 
coefplot (r*, keep(placebo_treat*) mlcolor(gs12) msize(medsmall) ciopts(color(gs12)) lcolor(gs12))  
         (r1, keep(rand_treat_mgt) mfcolor(black) mlcolor(black) msymbol(D) ciopts(color(black))), 
		 vertical yline(0) lcolor(red) coeflabels(r* = "") ytitle(Coefficient Estimate for Workers Leaving Firm) 
		 xtitle(Estimate Ranking) xlabel(0(10)200) sort 
		 levels(99) scheme(plotplain)
		 legend(order(2 "Placebo coefficient" 1 "Placebo 99% CI" 4 "Treatment coefficient") position(6) row(1));

# delimit cr 

* placebo test for total KPI (Team level)
	
	** Collapse to team level 
	sort team_al year
	drop if (team_al==team_al[_n-1] & year==year[_n-1]) 

eststo clear 
unab treatmentvarlist: team_rand_treat_mgt placebo_treat*
di "`treatmentvarlist'"
sort team_al year 

	** Fill in missing lag_KPI_ttlsc_avg3
	replace lagdepvar=lag_KPI_ttlsc_avg3
	
forvalues i = 1/201 {
	local treatmentvar : word `i' of `treatmentvarlist'
	xi: regress KPI_ttlsc_avg3 `treatmentvar' team_rand_treat_peer lagdepvar i.rand_strata_team if year==2017,cluster(team_al)
	estimates store r`i'
}	 

#delimit ;
coefplot(r*, keep(placebo_treat*) mcolor(gs12) msize(medsmall) ciopts(color(gs12)) lcolor(gs12)) 
	    (r1, keep(team_rand_treat_mgt) mfcolor(black) mlcolor(black) msymbol(D) ciopts(color(black))), 
		vertical yline(0) coeflabels(r* = "") ytitle(Coefficient estimate for Total KPI) 
		xtitle(Estimate Ranking) xlabel(0(10)200) sort 
        levels(95) scheme(plotplain)
		legend(order(2 "Placebo coefficient" 1 "Placebo 95% CI" 4 "Treatment coefficient") position(6) row(1));
#delimit cr	


 ****************************
 *							*
 *		  Figure O1.1		*
 *							*
 ****************************  
use KPI_Performance_allmonths,clear
		
* performance metric by tenure (as measured in quarter)
bys quarters_since_workstart: egen pfm_production_mean_byq_wkstart = mean(pfm_Production)	
bys quarters_since_workstart: egen pfm_ttl_mean_byq_wkstart = mean(pfm_totalscore)
	
* graph
graph twoway connected pfm_production_mean_byq_wkstart quarters_since_workstart ///
		if months_since_workstart <= 12, lpattern(dash) lcolor(black) ///
	title("", size(medium)) ///
	xtitle("Quarters since Work Start", size(small)) ///
	ytitle("Mean Production Performance Score", size(small)) ///
	xlab(0(1)4)  ysc(ra(-0.1 0.1)) ylab(-0.1(0.05)0.1)
